package com.fjnldx.mes.mapper.scheduling;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fjnldx.mes.domain.domainReq.*;
import com.fjnldx.mes.domain.pojo.Scheduling;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface SchedulingMapper extends BaseMapper<Scheduling> {

    /**
     * 人员管理-集团-级联
     */
    @Select("SELECT DISTINCT `group` FROM scheduling_personnel")
    List<Group> queryPersonnelGroup();

    /**
     * 人员管理-集团-组织
     */
    @Select("SELECT DISTINCT `group`,org FROM scheduling_personnel WHERE `group`=#{group}")
    List<GroupAndOrg> queryPersonnelGroupAndOrg(Group data);

    /**
     * 获取机台选择状态
     */
    //@Select("SELECT a.devSn,IFNULL(b.status,IF(a.pz=#{pz},'0','2')) `status`,IFNULL(a.devSelectedNumber,'0') devSelectedNumber FROM\n" +
    //        "(\n" +
    //        "SELECT a.*,b.devSelectedNumber FROM\n" +
    //        "(SELECT devSn,pz FROM mes_newscjh WHERE DATEDIFF(time,#{time})=0 AND org=#{org} AND cj=#{cj} AND gongxu=#{gongxu} ) a\n" +
    //        "LEFT JOIN\n" +
    //        "(SELECT devSn,COUNT(devSn) AS devSelectedNumber FROM scheduling WHERE DATEDIFF(start_time,#{time})=0 AND bc=#{bc} AND current_gongxu=#{gongxu} AND current_work_type=#{current_work_type} GROUP BY devSn) b \n" +
    //        "ON a.devSn=b.devSn\n" +
    //        ") a\n" +
    //        "LEFT JOIN\n" +
    //        "(\n" +
    //        "SELECT a.devSn,'1' `status` FROM scheduling a,mes_newscjh b \n" +
    //        "WHERE DATEDIFF(a.start_time,#{time})=0 AND a.gh=#{gh} AND a.bc=#{bc} AND a.current_gongxu=#{gongxu} AND a.current_work_type=#{current_work_type} AND DATEDIFF(b.time,now())=0 AND b.org=#{org} AND b.cj=#{cj} AND b.gongxu=#{gongxu} AND a.devSn=b.devSn\n" +
    //        " GROUP BY a.devSn) b\n" +
    //        "ON a.devSn=b.devSn")
    List<Map> getDevSnSelectedStatus(DevSnSelectedStatusReq data);

    /**
     * 查询络筒锭数选择状态
     */
    List<Map> getDsSelectedStatus(DsSelectedStatusReq data);

    /**
     * 获取机台设备号
     */
    @Select("SELECT equipment FROM system_mapping_equipment WHERE gongxu=#{gongxu}")
    List<Map<String, Object>> getEquipmentByGx(GongXu data);
}
